package com.mvc.common.service;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class CommonServiceProxy implements InvocationHandler {

	private Object obj;
	
	public CommonServiceProxy(){
		
	}
	
	public CommonServiceProxy(Object obj){
		this.obj = obj;
	}
	
	@Override
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		return method.invoke(obj, args);
	}
	
	public static Object getCommonServiceFactory(Class<?> cls){
		Object obj = null;
		try {
			obj = Proxy.newProxyInstance(cls.getClassLoader(), cls.getInterfaces(), new CommonServiceProxy(cls.newInstance()));
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return obj;
	}

}
